//
//  RenZProgressController.m
//  LuCaiZhu
//
//  Created by stella Ma on 2018/11/14.
//
#import "UIColor+NN.h"
#import "CKPuslichTool.h"
#import "RegularViewController.h"
#import "ProcessViewCell.h"
#import "UserModel.h"
#import "HandleNetProduct.h"
#import "NetworkConfig.h"
#import "myWebViewController.h"
#import "PersonalViewController.h"
#import "RenZProgressController.h"

@interface RenZProgressController ()
@property (weak, nonatomic) IBOutlet UITableView *mTableView;
@property (strong, nonatomic)NSArray *datas;
@end

@implementation RenZProgressController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"认证流程";
//    _datas = @[@{@"name":@"实名认证",@"statu":_dataDic[@"IDConfirm"]},
//               @{@"name":@"风险问卷调查",@"statu":_dataDic[@"InvestorConfirm"]},
//               @{@"name":@"合格投资者认定",@"statu":_dataDic[@"QuestionnaireFinish"]}];
    _mTableView.backgroundColor = [UIColor colorWithHexString:@"f4f4f4"];
    
    UIView *view = [[UIView alloc]init];
    view.frame = CGRectMake(0, 0, 80, 40);
    UIButton *left = [UIButton buttonWithType:UIButtonTypeCustom];
    left.frame = CGRectMake(-15, 0, 25, 40);
    [left setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [view addSubview:left];
    [left addTarget:self action:@selector(backTo:) forControlEvents:UIControlEventTouchUpInside];
    UIButton *label = [UIButton buttonWithType:UIButtonTypeCustom];
    label.frame = CGRectMake(CGRectGetMaxX(left.frame), 0, 80-CGRectGetWidth(left.frame), 40);
    [label setTitle:@"返回" forState:UIControlStateNormal];
    [label setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    label.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [label addTarget:self action:@selector(backTo:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:label];
    

    [self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:view]];
    
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self getConfirmStatus];
}

-(void)backTo:(UIButton *)bar {
//    if (self.returnBackBlock) {
//        self.returnBackBlock();
//    }
    NSDictionary *dic=@{@"index":@"0"};
    [[NSNotificationCenter defaultCenter]postNotificationName:@"goToOtherView" object:nil userInfo:dic];
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)getConfirmStatus{
    [HandleNetProduct getUserIDConfirmStatusForAccountPhone:[UserModel getUser].Phone Success:^(NSDictionary *data) {
        _datas = @[@{@"name":@"实名认证",@"status":data[@"IDConfirm"]},
                   @{@"name":@"风险问卷调查",@"status":data[@"QuestionnaireFinish"]},
                   @{@"name":@"合格投资者认定",@"status":data[@"InvestorConfirm"]}];
        [_mTableView reloadData];
    } Failure:^(NSString *errorInfo) {
        
    }];
}

- (void)MyButtonPresss:(UIButton *)sender {
    NSDictionary *dic = _datas[sender.tag];
    if ([dic[@"status"] isEqualToString:@"完成"]) {
        return;
    }
    switch (sender.tag) {
        case 0:
        {
            //实名认证
            PersonalViewController *vc = (PersonalViewController *)[CKPuslichTool getViewControllerFromStroyBoard:@"Setting" viewID:@"PersonalViewController"];
            
            [self.navigationController pushViewController:vc
                                                 animated:YES];
        }
            break;
        case 1:
        {
            //风险问卷调查
            
            myWebViewController *vc=(myWebViewController *)[CKPuslichTool getViewControllerFromStroyBoard:@"Setting" viewID:@"myWebViewController"];
            vc.title=@"风险评测";
            UserModel *mode=[UserModel getUser];
//            if (myType.length>0) {
//                vc.urlString=[NSString stringWithFormat:@"%@?CustomerId=%@",API_FXPC,mode.CustomerID];
//            }else{
                vc.urlString=[NSString stringWithFormat:@"%@?CustomerId=%@&MobilePhone=%@",API_FXPC,mode.CustomerID,mode.Phone];
//            }
            
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2:
        {
            //合格投资者认定
            RegularViewController *vc = (RegularViewController *)[CKPuslichTool getViewControllerFromStroyBoard:@"Setting" viewID:@"RegularViewController"];
            [vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
            [vc setModalPresentationStyle:UIModalPresentationOverFullScreen];
            vc.returnBlock = ^{
                [self getConfirmStatus];
            };
            [self presentViewController:vc animated:YES completion:nil];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - Table view data source
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 89;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    ProcessViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ProcessViewCell"];
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor clearColor];
    NSDictionary *dic = _datas[indexPath.row];
    if (indexPath.row == 0) {
        cell.topline.hidden =  YES;
        cell.downline.hidden =  NO;
    }else if (indexPath.row == _datas.count - 1) {
        cell.topline.hidden =  NO;
        cell.downline.hidden =  YES;
    }else{
        cell.topline.hidden =  NO;
        cell.downline.hidden =  NO;
    }
    cell.name.text = dic[@"name"];
    cell.status = dic[@"status"];
    cell.myButton.tag = indexPath.row;
    [cell.myButton addTarget:self action:@selector(MyButtonPresss:) forControlEvents:UIControlEventTouchDown];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.01f;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01f;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}


@end
